<?php $this->load->view('common/head');?>
<?php $this->load->view('common/navbar');?>
<form class="form-inline" name="add" id="add" action="<?php echo $this->input->server('REQUEST_URI'); ?>" method="post">
	<input type="hidden" name="level" id="level" value="<?=$level?>">
	<table class="table table-bordered">
		<thead>
			<tr>
        		<th class="bg-primary" colspan="4">补报基本信息</th>
        	</tr>
    	</thead>
    <tbody>
    	<tr>
    		<td class="col-md-1">年份：</td>
    		<td colspan="3">
    			<div class="form-group">
    			<select class="form-control" required style="width: 150px;" id="year" name="year">
			      <option value="">请选择</option>
				</select>
				</div>
    		</td>
    	</tr>
    	<tr>
    		<td class="col-md-1">双月：</td>
    		<td colspan="3">
    			<div class="form-group">
    			<select class="form-control" required style="width: 150px;" id="timeUnit" name="timeUnit">
			      <option value="">请选择</option>
				</select>
				</div>
    		</td>
    	</tr>
    	<tr>
    		<td class="col-md-1">开始时间：</td>
    		<td>
    			<div class="form-group">
    			<input type="text" class="form-control" style="width: 200px;" required onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'#F{$dp.$D(\'endTime\')}'})" name="startTime" id="startTime" value="" placeholder="开始时间" <?php if ($this->user['userRole'] == $this->userLib->roleArea){echo 'data-toggle="tooltip" data-placement="right" title="截止时间为双月结束后第20日24:00"';} ?>>
    			</div>
    		</td>
    		<td class="col-md-1">结束时间：</td>
    		<td>
    			<div class="form-group">
    			<input type="text" class="form-control" style="width: 200px;" required onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'startTime\')}'})" name="endTime" id="endTime" value="" placeholder="结束时间" <?php if ($this->user['userRole'] == $this->userLib->roleArea){echo 'data-toggle="tooltip" data-placement="right" title="截止时间为双月结束后第20日24:00"';} ?>>
    			</div>
    		</td>
    	</tr>
    </tbody>
	</table>
		<table class="table table-bordered">
		<thead>
			<tr>
        		<th class="bg-primary" colspan="3">补报专营店</th>
        	</tr>
    	</thead>
	    <tbody>
	    	<tr>
	    		<td colspan="3">
	    			<div class="form-group">
					    <label for="area">地区:</label>
					    <select class="form-control" id="area" name="area">
						  <option value="">请选择地区</option>
						</select>
					  </div>
					  <div class="form-group">
					    <label for="region">大区:</label>
					    <select class="form-control" id="region" name="region">
						  <option value="">请选择大区</option>
						</select>
					  </div>
					  <div class="form-group">
					    <label for="province">省份:</label>
					    <select class="form-control" id="province" name="province">
						  <option value="">请选择省份</option>
						</select>
					  </div>
					  <div class="form-group">
					    <label for="keyword">关键字：</label>
					    <input type="text" class="form-control" name="keyword" id="keyword" value="<?=$keyword?>" placeholder="关键字">
					  </div>
					  <div class="form-group">
					  	<button type="button" id="searchStore" class="btn btn-default btn-primary">搜索</button>
					  </div>
	    		</td>
	    	</tr>
	    	<tr>
	    		<td align="right">
	    			<select size="11" style="width:200px;" multiple="multiple" id="searchStoreList">
                    </select>
	    		</td>
	    		<td class="col-md-1" align="center">
	    			<button type="button" id="btnAddAll" style="margin: 5px;" class="btn btn-default">全选</button>
	    			<button type="button" id="btnAdd" style="margin: 5px;" class="btn btn-default">&nbsp;&gt;&gt;&nbsp;&nbsp;</button>
	    			<button type="button" id="btnRemove" style="margin: 5px;" class="btn btn-default">&nbsp;&lt;&lt;&nbsp;&nbsp;</button>
	    			<button type="button" id="btnRemoveAll" style="margin: 5px;" class="btn btn-default">清空</button>
	    		</td>
	    		<td>
	    			<select size="11" style="width:200px;" multiple="multiple" id="selectedStoreList" name="selectedStoreList[]"></select>
	    		</td>
	    	</tr>
	    	<tr>
	    		<td align="center" colspan="3">
	    			<button type="submit" class="btn btn-default btn-primary">保存</button>
	  				<button type="button" onclick="history.go(-1);" class="btn btn-default btn-primary">取消</button>
	    		</td>
	    	</tr>
	    </tbody>
	</table>
</form>
<script type="text/javascript">
	$(function(){
		$('[data-toggle="tooltip"]').tooltip();
		//Init Validation
  		initValidation();
		loadYearList('year',<?=$year ? $year : 0?>);
	    loadTimeUnitList('timeUnit',<?=$year ? $year : 0?>,<?=$timeUnit ? $timeUnit : 0?>);
		loadPlaceList('area', 'area', '', '<?=$area?>');
		loadPlaceList('region', 'region', '<?=$area?>', '<?=$region?>');
		loadPlaceList('province', 'province', '<?=$region?>', '<?=$province?>');
		loadPlaceList('city', 'city', '<?=$province?>', '<?=$city?>');
		loadPlaceList('storeId', 'store', '<?=$city?>', '<?=$storeId?>');
	});
    $("#year").change(function(){
      loadTimeUnitList('timeUnit',this.value);
    });
	$('#area').change(function(){
		loadPlaceList('region', 'region', this.value, '');
		loadPlaceList('province', 'province', '', '');
		loadPlaceList('city', 'city', '', '');
		loadPlaceList('storeId', 'store', '', '');
	});
	$('#region').change(function(){
		loadPlaceList('province', 'province', this.value, '');
		loadPlaceList('city', 'city', '', '');
		loadPlaceList('storeId', 'store', '', '');
	});
	$('#province').change(function(){
		loadPlaceList('city', 'city', this.value, '');
		loadPlaceList('storeId', 'store', '', '');
	});
	$('#city').change(function(){
		loadPlaceList('storeId', 'store', this.value, '');
	});
	//搜索专营店
	$('#searchStore').click(function(){
		searchStoreOnSelected('searchStoreList');
	});

	//移到右边
	$('#btnAdd').click(function(){
		//获取选中的选项，删除并追加给对方
		$('#searchStoreList option:selected').appendTo('#selectedStoreList');
	});
	
	//移到左边
	$('#btnRemove').click(function(){
		$('#selectedStoreList option:selected').appendTo('#searchStoreList');
	});
	
	//全部移到右边
	$('#btnAddAll').click(function(){
		//获取全部的选项,删除并追加给对方
		$('#searchStoreList option').appendTo('#selectedStoreList');
	});
	
	//全部移到左边
	$('#btnRemoveAll').click(function(){
		$('#selectedStoreList option').appendTo('#searchStoreList');
	});
	
	//双击选项
	$('#searchStoreList').dblclick(function(){ //绑定双击事件
		//获取全部的选项,删除并追加给对方
		$("option:selected",this).appendTo('#selectedStoreList'); //追加给对方
	});
	
	//双击选项
	$('#selectedStoreList').dblclick(function(){
		$("option:selected",this).appendTo('#searchStoreList');
	});
/**
 * 重启验证
 * @return {[type]} [description]
 */
function initValidation() {
  $('form[name="add"]').find("input,select,textarea").jqBootstrapValidation("destroy");
  $('form[name="add"]').find("input,select,textarea").not("[type=submit]").jqBootstrapValidation({
    preventSubmit:false,
    submitSuccess: function (form, event) {
         event.preventDefault();
         $("#selectedStoreList option").attr("selected", true);
         ajaxFormSubmit('add');
     },
     submitError: function (form, event, errors) {
       event.preventDefault();
     }
  });
}
</script>
<?php $this->load->view('common/foot');?>